module Main where

import TM
import Data.Time.Clock (diffUTCTime, getCurrentTime)
import System.Environment (getArgs)

-- args: <tape file> <transitions file> <q0> <trace?> (`true' or `false')
main = do
    args <- getArgs
    start <- getCurrentTime
    case length args of
        4 -> run args
        _ -> error "incorrect number of arguments"
    finish <- getCurrentTime
    print $ diffUTCTime finish start
    
run args = do
    tp <- readFile (args !! 0)
    tr <- readFile (args !! 1)
    (f (args !! 3)) (makeTM tp tr (read $ args !! 2))
    where f t | t == "true"  = trace
              | t == "false" = simulate
              | otherwise    = error "fourth argument must be true or false"
